#!/bin/bash
# 宿主机环境收集脚本

echo "开始收集系统环境信息..."
DEST_DIR="/tmp/prod-sync"
rm -rf "$DEST_DIR" 2>/dev/null
mkdir -p "$DEST_DIR"

{
    # 收集系统信息
    lscpu > "$DEST_DIR/lscpu.txt"
    free -h > "$DEST_DIR/meminfo.txt"
    cp /etc/resolv.conf "$DEST_DIR/"
    cp /etc/sysctl.conf "$DEST_DIR/" 2>/dev/null
    mkdir -p "$DEST_DIR/sysctl.d"
    cp /etc/sysctl.d/* "$DEST_DIR/sysctl.d/" 2>/dev/null
    cp /etc/security/limits.conf "$DEST_DIR/" 2>/dev/null
    
    # 打包环境配置
    tar -czf /tmp/prod-sync.tar.gz -C "$DEST_DIR" .
} &> /dev/null

echo "环境信息已打包至: /tmp/prod-sync.tar.gz"
echo "收集内容:"
find "$DEST_DIR" -type f | sed 's|^|  |'